#include <iostream>
#include<string>
using namespace std;


void test_string1()
{
	string s0("hello world");
	string s1;
	string s2(s0);
	string s3(s0, 1, 1);
	string s4(6, '$');
	string s5(s0, 6);
}
void test_string2()
{
	string s1 = "abcd";
	string s2 = s1;
	string s3 = "a";

	cout << s1 << endl;
	cout << s2 << endl;
	cout << s3 << endl;

}
void test_string3()
{
	string s1("hello world");

	string::iterator it = s1.begin();
	while (it != s1.end())
	{
		cout << *it;
		it++;
	}
	cout << endl;

	string::reverse_iterator rit = s1.rbegin();
	while (rit != s1.rend())
	{
		cout << *rit;
		rit++;
	}
	cout << endl;


	const string s2("abcdefg");
	string::const_iterator cit = s2.begin();
	while (cit != s2.end())
	{
		cout << *cit;
		cit++;
	}
	cout << endl;

}

void test_string4()
{
	string s1("abcdefg");
	cout << s1 << endl;
	cout << s1.size() << endl;
	cout << s1.capacity() << endl;

		
	s1.resize(20);
	cout << s1 << endl;
	cout << s1.size() << endl;
	cout << s1.capacity() << endl;

	s1.clear();
	cout << s1 << endl;
	cout << s1.size() << endl;
	cout << s1.capacity() << endl;
	
	s1.shrink_to_fit();
	cout << s1 << endl;
	cout << s1.size() << endl;
	cout << s1.capacity() << endl;
}

void test_string5()
{
	string s1("hello world");
	for (int i = 0; i < s1.size(); i++)
	{
		cout << s1.at(i) << " ";
	}
	cout << endl;

	cout << s1.front() << endl;
	cout << s1.back() << endl;

	s1.append(s1);
	cout << s1 << endl;

	s1.assign("aaaaaaaaa");
	cout << s1 << endl;

	s1.replace(0, 1, "bbbbbbbb");
	cout << s1 << endl;

	string s2("hello world");
	s1.swap(s2);
	cout << s1 << endl;
	cout << s2 << endl;

	s1.insert(11, " hello zy");
	cout << s1 << endl;

	s1.erase(6, 5);
	cout << s1 << endl;

}
void test_string6()
{
	string s1("hello hello worlf world");

	size_t pos1 = s1.find(' ');
	cout << pos1 << endl;

	size_t pos2 = s1.rfind(' ');
	cout << pos2 << endl;

	size_t pos = s1.find_first_of("lo");
	while (pos != string::npos)
	{
		s1[pos] = '$';
		pos = s1.find_first_of("lo");
	}
	cout << s1 << endl;

	cout << s1.empty() << endl;
	s1.clear();
	cout << s1.empty() << endl;
}
void test_string7()
{
	string s1("hello world");
	cout << s1.size() << endl;
	s1 += " hello zy";
	cout << s1 << endl;
	cout << s1.size() << endl;
	s1.append(" hello linux");
	cout << s1 << endl;
	s1.push_back('6');
	s1.push_back('6');
	s1.push_back('6');
	cout << s1 << endl;

	s1.assign("hello linux");
	cout << s1 << endl;

	string s2 = "hello world";
	s1.swap(s2);
	cout << s1 << endl;
	cout << s2 << endl;
}
void test_string8()
{
	string s1("hello world");
	const char* p = s1.data();
	cout << p << endl;
	const char* p2 = s1.c_str();
	cout << p2 << endl;
}
void print(const string& s)
{
	string protocol, domain, uri;
	size_t pos1 = s.find(':');
	if (pos1 != string::npos)
	{
		protocol = s.substr(0, pos1 - 0);
		cout << protocol << endl;
	}

	size_t pos2 = s.find('/', pos1 + 3);
	if (pos2 != string::npos)
	{
		domain = s.substr(pos1 + 3, pos2 - pos1 - 3);
		cout << domain << endl;
	}

	uri = s.substr(pos2 + 1);
	cout << uri << endl;
}
void test_string9()
{
	string s("https://legacy.cplusplus.com/reference/string/string/find/");
	string s2("https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&tn=baidu&wd=allocator&fenlei=256&oq=sequence&rsv_pq=adab4f8d002bac2f&rsv_t=9a2etArjbKIR%2Ber8XX4mVmra2TAQNXovVVhSjycb%2Bx1g2ROlVpW%2Fa%2ByCVyM&rqlang=cn&rsv_dl=tb&rsv_enter=1&rsv_btype=t&inputT=550&rsv_n=2&rsv_sug3=23&rsv_sug1=17&rsv_sug7=100&rsv_sug2=0&rsv_sug4=550&rsv_sug=2");
	print(s);
	print(s2);

	size_t a = -1;
	cout << a << endl;
	cout << s.max_size() << endl;
}
void test_string10()
{
	string s0;
	cin >> s0;
	cout << s0 << endl;
	string s;
	getline(cin, s);
	cout << s << endl;
}
int main()
{
	test_string9();


	return 0;
}